package com.mxsat.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mxsat.common.annotation.ResponseResult;
import com.mxsat.common.layui.tree.LayTree;
import com.mxsat.common.result.PlatformResult;
import com.mxsat.system.entity.SysMenu;
import com.mxsat.system.service.SysMenuService;
import com.mxsat.system.tree.MenuTreeStrategy;

@ResponseResult(PlatformResult.class)
@RestController
@RequestMapping("/*")
public class SystemMenuController {

	@Autowired
	private SysMenuService sysMenuService;
	
	@GetMapping("/Menus")
	public Page<SysMenu> menus() throws Exception {
		Page<SysMenu> page = new Page<>();
		return (Page<SysMenu>) sysMenuService.findSysMenusByPage(page );
	}
	
	@GetMapping("/MenusTree")
	public List<LayTree> menusTree() throws Exception {
		return new MenuTreeStrategy(sysMenuService.findSysMenuByAll()).transforLayTree();
	}
	
	@GetMapping("/Menu/{mid}")
	public SysMenu menuInfo(@PathVariable Long mid) throws Exception{
		return sysMenuService.findSysMenuById(mid);
	}
	
	@RequestMapping(value="/Menu",method=RequestMethod.POST)
	public String addMenu(SysMenu menu) throws Exception{
		sysMenuService.addSysMenu(menu);
		return "添加菜单成功";
	}
	
	@RequestMapping(value="/Menu",method=RequestMethod.PUT)
	public String modifyMenu(SysMenu menu) throws Exception{
		sysMenuService.modifySysMenu(menu);
		return "修改菜单成功";
	}
}
